package blue.starter.internal.mqtt.config;

import blue.starter.internal.mqtt.property.MqttProperties;
import blue.starter.mqtt.MqttConsumer;
import blue.starter.mqtt.MqttProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * @author Jin Zheng
 * @since 1.0 2020-07-15
 */
@Configuration
@EnableConfigurationProperties(MqttProperties.class)
@ConditionalOnProperty(prefix = "blue.mqtt", name = "enabled", havingValue = "true")
public class MqttAutoConfiguration
{
	private Map<String, MqttProducer> producerMap;
	private Map<String, MqttConsumer> consumerMap;

	public MqttAutoConfiguration()
	{
	}

	@Bean
	public static MqttBeanPostProcessor beanPostProcessor()
	{
		return new MqttBeanPostProcessor();
	}

	@Autowired
	public void setProducerMap(Map<String, MqttProducer> producerMap)
	{
		this.producerMap = producerMap;
	}

	@Autowired
	public void setConsumerMap(Map<String, MqttConsumer> consumerMap)
	{
		this.consumerMap = consumerMap;
	}
}
